package com.alatus;

import com.alatus.utils.GameUtil;
import java.awt.*;

/**
 * Created by Administrator on 2017/4/16.
 * 底层地图
 * 绘制游戏相关组件
 * author:Alatus
 */
public class MapBottom {
    private BottomMine bottomMine = new BottomMine();
    private BottomNum bottomNum = new BottomNum();
    {
        bottomMine.newMine();
        bottomNum.newNum();
    }
//    重置游戏
    void reGame(){
        for (int i = 1; i <= GameUtil.MAP_WIDTH; i++) {
            for (int j = 1; j <= GameUtil.MAP_HEIGHT; j++) {
                GameUtil.DATA_BOTTOM[i][j] = 0;
            }
        }
        bottomMine.newMine();
        bottomNum.newNum();
    }
    void paintSelf(Graphics graphics){
        graphics.setColor(Color.RED);
        for (int i = 0; i <= GameUtil.MAP_WIDTH; i++) {
            graphics.drawLine(GameUtil.OFFSET + i * GameUtil.SQUARE_LENGTH,
                    3 * GameUtil.OFFSET,
                    GameUtil.OFFSET + i * GameUtil.SQUARE_LENGTH,
                    3 * GameUtil.OFFSET+GameUtil.MAP_HEIGHT * GameUtil.SQUARE_LENGTH);
        }
        for (int i = 0; i <= GameUtil.MAP_HEIGHT; i++) {
            graphics.drawLine(GameUtil.OFFSET,
                    3 * GameUtil.OFFSET + i * GameUtil.SQUARE_LENGTH,
                    GameUtil.OFFSET + GameUtil.MAP_WIDTH * GameUtil.SQUARE_LENGTH,
                    3 * GameUtil.OFFSET + i * GameUtil.SQUARE_LENGTH);
        }
        for (int i = 1; i <= GameUtil.MAP_WIDTH; i++) {
            for (int j = 1; j <= GameUtil.MAP_HEIGHT; j++) {
//                地雷
                if(GameUtil.DATA_BOTTOM[i][j] == -1){
                    graphics.drawImage(GameUtil.mine,
                            GameUtil.OFFSET + (i - 1) * GameUtil.SQUARE_LENGTH + 1,
                            GameUtil.OFFSET * 3 + (j - 1) * GameUtil.SQUARE_LENGTH + 1,
                            GameUtil.SQUARE_LENGTH - 2,
                            GameUtil.SQUARE_LENGTH - 2,
                            null);
                }
//                数字
                if(GameUtil.DATA_BOTTOM[i][j] >= 0){
                    graphics.drawImage(GameUtil.images[GameUtil.DATA_BOTTOM[i][j]],
                            GameUtil.OFFSET + (i - 1) * GameUtil.SQUARE_LENGTH + 1,
                            GameUtil.OFFSET * 3 + (j - 1) * GameUtil.SQUARE_LENGTH + 1,
                            GameUtil.SQUARE_LENGTH - 2,
                            GameUtil.SQUARE_LENGTH - 2,
                            null);
                }
            }
        }
//        绘制数字
        GameUtil.drawWord(graphics,"未找出:" +(GameUtil.MINE_MAX-GameUtil.FLAG_NUM),GameUtil.OFFSET,2*GameUtil.OFFSET,30,Color.red);
//        倒计时
        GameUtil.drawWord(graphics,(GameUtil.END_TIME-GameUtil.START_TIME) / 1000+"秒",
                GameUtil.OFFSET + GameUtil.SQUARE_LENGTH * (GameUtil.MAP_WIDTH - 1),2*GameUtil.OFFSET,30,Color.red);
        switch (GameUtil.state){
            case 0:
                GameUtil.END_TIME = System.currentTimeMillis();
                graphics.drawImage(GameUtil.flag,
                        GameUtil.OFFSET + GameUtil.SQUARE_LENGTH * (GameUtil.MAP_WIDTH / 2),
                        GameUtil.OFFSET,
                        null);
                break;
            case 1:
                graphics.drawImage(GameUtil.top,
                        GameUtil.OFFSET + GameUtil.SQUARE_LENGTH * (GameUtil.MAP_WIDTH / 2),
                        GameUtil.OFFSET,
                        null);
                break;
            case 2:
                graphics.drawImage(GameUtil.wrongFlag,
                        GameUtil.OFFSET + GameUtil.SQUARE_LENGTH * (GameUtil.MAP_WIDTH / 2),
                        GameUtil.OFFSET,
                        null);
                break;
        }
    }
}
